class CreateInitialSchemas < ActiveRecord::Migration
  def self.up
    create_table :foods do |t|  # these are the ingredients, if in a recipe, or end nutrients if prepared food
      t.column :name, :string, :limit => 30, :null => false
      t.column :serving_size, :float, :null => false
      t.column :serving_size_units,  :integer, :null => false
      t.column :calories, :float, :null => false
      t.column :fat_calories, :float, :null => false
      t.column :saturated_fat_calories, :float, :null => false
      t.column :stearic_acid, :float, :null => true
      t.column :total_fat, :float, :null => false
      t.column :saturated_fat, :float, :null => false
      t.column :trans_fat, :float, :null => false
      t.column :poly_unsaturated_fat, :float, :null => true
      t.column :mono_unsaturated_fat, :float, :null => true
      t.column :cholesterol, :float, :null => false
      t.column :sodium, :float, :null => false
      t.column :total_carbs, :float, :null => false
      t.column :other_carbs, :float, :null => true
      t.column :dietary_fiber, :float, :null => false
      t.column :soluable_fiber, :float, :null => true
      t.column :insoluable_fiber, :float, :null => true
      t.column :sugars, :float, :null => false
      t.column :sugar_alcohol, :float, :null => true
      t.column :protein, :float, :null => false
      t.column :vitamin_a, :float, :null => false
      t.column :percent_a_beta_carotene, :float
      t.column :vitamin_c, :float, :null => false
      t.column :potasium, :float, :null => true
      t.column :calcium, :float, :null => false
      t.column :iron, :float, :null => false
      #  and maybe the list of other nutrients ... :-)
    end
    
    create_table :measurements do |t|
      t.column  :name, :string, :limit => 30, :null => false
      t.column  :abbreviation, :string, :limit => 6, :null => true
      t.column  :ratio, :float, :null => false
      t.column  :measurement_type_id, :integer, :null => false
      t.column  :measurement_id, :integer, :null => false
    end
    
    create_table :budgets do |t|
      t.column :carbs, :float, :null => false
      t.column :fats, :float, :null => false
      t.column :calories, :float, :null => false
    end
    
    create_table :measurement_types do |t|
      t.column   :name, :string, :limit => 30, :null => false
    end
    
    create_table :recipes do |t|
      t.column  :name, :string, :limit => 30, :null => false
      t.column  :directions, :text, :null => true
    end
    
    create_table :ingredients do |t|
      t.column  :name, :string, :limit => 30, :null => false
      t.column  :amount, :float, :null => false
      t.column  :measurement_id, :integer, :null => false
      t.column  :food_id, :integer, :null => false
    end
    
    create_table :meals do |t|
      t.column  :name, :string, :limit => 30, :null => false
    end
    
    create_table :diets do |t|
      t.column  :name, :string, :limit => 30, :null => false
    end
  end
  
  def self.down
    drop_table :foods
    drop_table :measurements
    drop_table :measurement_types
    drop_table :recipes
    drop_table :ingredients
    drop_table :meals
    drop_table :diets
    drop_table :budgets
  end
end
